package com.yx;

import com.alibaba.fastjson.JSONObject;
import lombok.Cleanup;
import lombok.Data;
import lombok.SneakyThrows;
import org.zjt.demo.common.ErrorMsgEnum;
import org.zjt.demo.model.Trade;
import org.zjt.demo.model.Trade2;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created by zjt on 2017/3/2.
 */
public class Start {

    @SneakyThrows(Exception.class)
    public static void main(String[] args) {
        //System.out.println(JSONObject.toJSONString(ErrorMsgEnum.NOT_FOUND.getJsonResult()));
        //System.out.println(JSONObject.toJSONString(ErrorMsgEnum.UNAUTHORIZED.getJsonResult()));

        Trade trade = new Trade("id");
        trade.setPrice(9.00);
        System.out.println(trade.toString());


        Trade2 trade2 = Trade2.builder().id("1").name("juntao").occupation("occupation").price(2.34).build();
        System.out.println(trade2.toString());


       /* // TODO: 2017/5/18   TreeSet 不能存放非Comparable子类
        Set<Trade2> set = new TreeSet<Trade2>();
        set.add(trade2);
        set.forEach(System.out::println);

        */




        /**
         * 上界：<? extends T>     ?是T的子类
         *
         *      参数化类型的可能是T 或是 T的子类;
         *
         *
         *
         * 下界：<? super T>       ?是T的父类
         *
         *      参数化类型是此类型的超类型（父类型），直至Object;
         *
         */

        List<? super Super> list= new ArrayList<>();
        Son son = new Son();
        list.add(son);
        list.forEach(System.out::println);


        List<? extends Super> list2 ;
        List<Son> data =  new ArrayList<>();
        data.add(son);
        list2 = data;
        list2.forEach(System.out::println);

        /**
         * ERROR:
         *
         *    list = new ArrayList<Son>();
         *
         *    list2 = new ArrayList<Object>();
         */



    }



}

@Data
class Super {
    private int id;
}


@Data
class Son extends Super{
    private String name ;
}